package com.burgeon.backend.SHOP.rest.recharger;
/**
 * 新增充值单
 */

import com.burgeon.backend.Rest.base.RESTBase;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

public class CreateRECHARGE extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public CreateRECHARGE(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }
    /**
     * 发送并接收字符
     */
    public String getData(String phone,String price,String presenter,String xsdh) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";

        String str = RESULT(Data(phone,price,presenter,xsdh), url);
        System.err.println(str);
        String code = new JSONArray(str).getJSONObject(0).getString("code");
        String message = new JSONArray(str).getJSONObject(0).getString("message");
        if (!"0".equals(code)) {
            throw new Exception(message);
        }
        return new JSONArray(str).getJSONObject(0).getString("objectid");
    }

    private MultiValueMap Data(String phone, String price, String presenter, String xsdh) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        HashMap params = new HashMap();
        params.put("'C_VIP_ID__CARDNO'",phone);
        params.put("TOT_AMT_DEPOSIT","'"+price+"'");
        params.put("TOT_AMT_GIVE","'"+presenter+"'");
        params.put("DESCRIPTION","由小程序商城生成");//商品质量
        params.put("BILLDATE",sdf.format(new Date()));
        params.put("XSNO",xsdh);

        params.put("table", "YC_VIPMONEY");//表名

        return DATA("ObjectCreate", params, account, password);
    }
    public static void main(String[] args) {

        CreateRECHARGE g = new CreateRECHARGE("47.92.53.75:90", "dy@xcx.com", "123");

        try {

            System.err.println(g.getData("17732141036","20","0","123"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
